Skip to content

Enable segmentwise recompression for nullable order by columns with firstlast metadata index - #9963

Merged
natalya-aksman merged 1 commit into
mainfrom
enable_segmentwise_recompress_for_nullable_orderby_with_firstlast
Jun 11, 2026
Merged

Enable segmentwise recompression for nullable order by columns with firstlast metadata index#9963
natalya-aksman merged 1 commit into
mainfrom
enable_segmentwise_recompress_for_nullable_orderby_with_firstlast

Conversation

@natalya-aksman

@natalya-aksman natalya-aksman commented Jun 4, 2026

Copy link
Copy Markdown
Member

Removes restrictions on segmentwise recompression with nullable order by columns introduced to address #9444.
Now it is OK to segmentwise-recompress on nullable order by columns with firstlast indexes as #9784 have been implemented.

Using firstlast metadata with NULLs exposed a bug in slot_key_test in regards to matching a scan key to batches like [NULL, 10] or [10, NULL] which did not exist with minmax indexes, the bug is fixed now.

To enable segmentwise recompression for firstlast indexes it is also advisable to address leading column limitation on matching tuples to batches on multiple orderby keys. It was necessary limitation for minmax index but multikeys can be properly matched with firstlast indexes.

Reworking multikey tuple to batch matching for firstlast could be done in a different PR.

Disable-check: force-changelog-file

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

@Poroma-Banerjee, @antekresic: please review this pull request.

Powered by pull-review

@natalya-aksman
natalya-aksman marked this pull request as draft June 4, 2026 19:44
Comment thread tsl/src/compression/recompress.c Outdated
/* compressed boundary is NULL */
if (is_null)
{
if (min_bound)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this means. Can there be a comment to explain?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic was moved to slot_key_test as it's a better fit, see comments there.

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tsl/src/compression/compression_scankey.c 71.42% 0 Missing and 2 partials ⚠️
tsl/src/compression/api.c 88.88% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@natalya-aksman
natalya-aksman force-pushed the enable_segmentwise_recompress_for_nullable_orderby_with_firstlast branch from eafe9ea to e8f3046 Compare June 5, 2026 16:08
@natalya-aksman natalya-aksman added Columnstore Related to the column store / compression and removed Columnstore Related to the column store / compression labels Jun 5, 2026
@natalya-aksman
natalya-aksman marked this pull request as ready for review June 5, 2026 16:24
@github-actions
github-actions Bot requested review from kpan2034 and pnthao June 5, 2026 16:24
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

@kpan2034, @pnthao: please review this pull request.

Powered by pull-review

@natalya-aksman
natalya-aksman requested review from akuzm and svenklemm and removed request for kpan2034 and pnthao June 5, 2026 16:24
*
* If slot attribute is NULL and key is NOT NULL,
* (key >= NULL) returns True for nulls_first
* and (key <= NULL) returns True for !nulls_first (i.e. for NULLS LAST).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is (key <= NULL)?

@natalya-aksman natalya-aksman Jun 8, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is (key <= NULL)?

not-NULL key value sorts before NULL, the comment can be changed to be more accurate.

@Poroma-Banerjee

Copy link
Copy Markdown
Member

is issue #9970 related?

@natalya-aksman

natalya-aksman commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

is issue #9970 related?

No, that issue is about renaming a column which is used in firstlast metadata, because metadata column names for firstlast are based on source column names, for example if we had firstlast index on column dev with metadata column names _ts_meta_v2_first_dev, _ts_meta_v2_last_dev, but then we renamed dev to sensor then metadata columns would no longer match sensor as we construct metadata column names from the source column name on the fly.

I.e. #9970 is completely unrelated.

}

/* NULL > key i.e. NULL sorts after key argument */
if (!nulls_first && (key->sk_strategy == BTGreaterStrategyNumber ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you have this check here, is handle_null_scan still needed separately?

@natalya-aksman natalya-aksman Jun 11, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the change in slot_key_test is about matching a boundary to the scan key, this method returns True if scan key fits the boundary and False otherwise, for example it is True for boundary = 5 and scan key (6, >=), i.e. (6 >= 5) = True.

We can now have Tuple_match result when key is not NULL but the boundary is NULL, i.e. for boundary = NULL, nullfirst = True and scan key (6, >=) we used to return False (no match) and now we return True (match as 6 sorts after NULL).

But we still need to handle cases of key = NULL or boundary = NULL when slot_key_test returns False. We need to check whether this tuple should go before or after a region defined by those boundaries, for example 6 goes before [10, NULL] for NULLS LAST scenario. So no change in logic for handle_null_scan, we just now return True from slot_key_test in more scenarios.

@natalya-aksman
natalya-aksman force-pushed the enable_segmentwise_recompress_for_nullable_orderby_with_firstlast branch from e8f3046 to 75cbaac Compare June 11, 2026 16:25
@natalya-aksman
natalya-aksman merged commit ba6bc78 into main Jun 11, 2026
57 of 58 checks passed
@natalya-aksman
natalya-aksman deleted the enable_segmentwise_recompress_for_nullable_orderby_with_firstlast branch June 11, 2026 19:14
kpan2034 pushed a commit to kpan2034/timescaledb that referenced this pull request Jul 1, 2026
…irstlast metadata index (timescale#9963)

Removes restrictions on segmentwise recompression with nullable order by
columns introduced to address timescale#9444.
Now it is OK to segmentwise-recompress on nullable order by columns with
firstlast indexes as
[timescale#9784](timescale#9784) have been
implemented.

Using firstlast metadata with NULLs exposed a bug in `slot_key_test` in
regards to matching a scan key to batches like [NULL, 10] or [10, NULL]
which did not exist with minmax indexes, the bug is fixed now.
@timescale-automation timescale-automation added the released-2.29.0 Released in 2.29.0 label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released-2.29.0 Released in 2.29.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants